cmake_minimum_required(VERSION 3.5)

project(rclc_tutorials)

if(NOT WIN32)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra -Wpedantic")
endif()

find_package(ament_cmake REQUIRED)
find_package(example_interfaces REQUIRED)
find_package(rclc REQUIRED)
find_package(rcl REQUIRED)
find_package(rmw REQUIRED)
find_package(rmw_implementation_cmake REQUIRED)
find_package(rmw_implementation REQUIRED)
find_package(std_msgs REQUIRED)

ament_package()

##
## Examples of Publish/Subscribe with Topics
##
macro(targets)
  if(NOT target_suffix STREQUAL "")
    get_rcl_information("${rmw_implementation}" "rcl${target_suffix}")
  endif()

  add_executable(talker${target_suffix}
    src/talker.c)
  ament_target_dependencies(talker${target_suffix}
    "rclc${target_suffix}"
    "rmw_implementation"
    "std_msgs")
  install(TARGETS talker${target_suffix}
    DESTINATION lib/${PROJECT_NAME})

  add_executable(listener${target_suffix}
    src/listener.c)
  ament_target_dependencies(listener${target_suffix}
    "rclc${target_suffix}"
    "rmw_implementation"
    "std_msgs")
  install(TARGETS listener${target_suffix}
    DESTINATION lib/${PROJECT_NAME})
endmacro()

call_for_each_rmw_implementation(targets GENERATE_DEFAULT)
